package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.SysUserDto;
import com.itheima.advantagesup.entity.PageBean;
import com.itheima.advantagesup.service.SysUserService;
import com.itheima.advantagesup.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 分页查询
     * @param page
     * @param limit
     * @param LoginName
     * @param status
     * @param phone
     * @return
     */
    @GetMapping("/sys_user/list")
    public R findAllUSer(@RequestParam(defaultValue ="1" ) Integer page,
                         @RequestParam(defaultValue ="10" ) Integer limit,String LoginName,
        Integer status,String phone){
        log.info("分页查询:{}{}{}{}{}",page,limit,LoginName,status,phone);
        PageBean pageBean= sysUserService.findAllUser(page,limit,LoginName,status,phone);
        return R.success(pageBean);
    }

    /**
     * 添加
     * @return
     */
    @PostMapping("/sys_user/add")
    public R add(@RequestBody SysUserDto sysUserDto){
        sysUserService.add(sysUserDto);
    return R.success();
    }

    /**
     *删除
     * @param id
     * @return
     */
    @GetMapping("/sys_user/del")
    public R del(String id){
        sysUserService.delete(id);
    return R.success();
    }

    /**
     * 根据id进行回显
     * @param id
     * @return
     */
    @GetMapping("/sys_user/rowInfo")
    public R rowInfo(String id){
        UserInfoVO userInfoVO =sysUserService.rowInfo(id);
        return R.success(userInfoVO);
    }

    @PostMapping("/sys_user/update")
    public R update(@RequestBody SysUserDto sysUserDto){
        sysUserService.update(sysUserDto);
        return R.success();
    }
}
